home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Languguage OS 2
/
Languguage OS II Version 10-94 (Knowledge Media)(1994).ISO
/
language
/
ici
/
ici.cpi
/
mkvar.c
< prev
next >
Wrap
C/C++ Source or Header
|
1994-10-27
|
2KB
|
71 lines
#include "exec.h"
#include "struct.h"
#include <stdarg.h>
/*
* mkvar(scope, name, typespec, value)
*
* This function is a simple way to define variables (to the ICI level).
* It takes a scope structure, name for the variable, a type specification
* (see below) and the variable's initial value and creates a variable in
* the current extern scope.
*
* Type specification is similar to other internal functions (ici_func,
* typecheck etc..) and uses the following key-letters
*
* Type Letter ICI type C type (of value)
* ================================================
* i int long
* f float double
* s string char *
* u file FILE *
* o any object_t *
*/
int
mkvar(struct_t *scope, char *name, int type, ...)
{
object_t *o;
string_t *n;
va_list va;
va_start(va, type);
switch (type)
{
case 'i':
o = objof(new_int(va_arg(va, long)));
break;
case 'f':
o = objof(new_float(va_arg(va, double)));
break;
case 's':
o = objof(new_cname(va_arg(va, char *)));
break;
case 'u':
if ((n = new_cname(name)) == NULL)
return 1;
o = objof(new_file((char *)va_arg(va, FILE *), &stdio_ftype, n));
loose(n);
break;
case 'o':
if ((o = va_arg(va, object_t *)) == NULL)
error = "NULL object pointer given to mkvar()";
break;
default:
error = "illegal type key-letter given to mkvar()";
return 1;
}
va_end(va);
if
(
o == NULL
||
(n = new_cname(name)) == NULL
||
assign(scope, n, o)
)
return 1;
loose(o);
loose(n);
return 0;
}